import com.fasterxml.jackson.databind.ObjectMapper;
import com.ujiuye.userjson.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet("/m2")
public class myServlet01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        User u1 = new User(1001,"牛魔王","男",new int[]{99,100,101});
        User u2 = new User(1002,"铁扇妹妹","女",new int[]{100,1002,97});
        ArrayList<User> list = new ArrayList<>();
        list.add(u1);
        list.add(u2);
        ObjectMapper mapper = new ObjectMapper();
        String s = mapper.writeValueAsString(list);
        //将数据响应回浏览器
        resp.getWriter().print(s);

    }
}
